package com.mogujie.tt.ui.fragment;

import android.content.Context;
import android.graphics.Rect;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.Selection;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.mogujie.tt.DB.entity.UserEntity;
import com.mogujie.tt.DB.sp.LoginSp;
import com.mogujie.tt.DB.sp.RegisterSp;
import com.mogujie.tt.R;
import com.mogujie.tt.config.SysConstant;
import com.mogujie.tt.imservice.service.IMService;
import com.mogujie.tt.imservice.support.IMServiceConnector;
import com.mogujie.tt.ui.adapter.QuanzDynamicAdapter;
import com.mogujie.tt.ui.adapter.QuanzDynamicAdapter.FlushListView;
import com.mogujie.tt.ui.helper.Emoparser;
import com.mogujie.tt.ui.widget.EmoGridView;
import com.mogujie.tt.ui.widget.IMBaseImageView;
import com.mogujie.tt.ui.widget.PublishLayout;
import com.mogujie.tt.ui.widget.QuanzQzMessageDetail;
import com.mogujie.tt.ui.widget.QuanzQzReply;
import com.mogujie.tt.utils.GETUtil;
import com.mogujie.tt.utils.IMUIHelper;
import com.mogujie.tt.utils.XListView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import de.greenrobot.event.EventBus;

/**
 * Created by 50281 on 2015/9/15.
 */
public class QuanzQzFragment extends MainFragment implements View.OnClickListener,XListView.IXListViewListener,PublishLayout.SoftListener {

    private View curView = null;
    private XListView listview = null;
    private List<QuanzQzMessageDetail> list;
    private QuanzDynamicAdapter adapter;
    private PopupWindow replyWindow;  // 评论window
    private PopupWindow editWindow;   // 回复window
    private EditText replyEdit;
    private TextView sendBtn;
    private InputMethodManager manager;
    private ImageButton discuss;// 评论
    private ImageButton favuor;// 赞
    private ImageButton favuorCancle;// 取消赞
    private View editView;
    private View mHeadViw;
    private Handler mHandler;
    private int mVisibleHeight,mHoadHeight,mEditHeight,id,screenHeight,result;
    private String login_name,login_password;
    private int Upwardmark=2;
    private Map<String,QuanzQzReply> map = null;
    private Map<String,Map<String,QuanzQzReply>> map1 = null;
    private ImageView reply_emo_btn;
    private ProgressBar progress_bar;
    private View emo_layout_publish;
    private EmoGridView emoGridView = null;
    private InputMethodManager inputManager = null;
    int rootBottom = Integer.MIN_VALUE, keyboardHeight = 0;

    private IMServiceConnector imServiceConnector = new IMServiceConnector(){

        @Override
        public void onServiceDisconnected() {}

        @Override
        public void onIMServiceConnected() {

            IMService imService = imServiceConnector.getIMService();
            if (imService == null) {
                return;
            }
            if (!imService.getContactManager().isUserDataReady()) {
                logger.i("detail#contact data are not ready");
            } else {
                init(imService);
            }
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        if (null != curView) {
            ((ViewGroup) curView.getParent()).removeView(curView);
            return curView;
        }
        curView = inflater.inflate(R.layout.quanz_fragment_qz, topContentView);
        EventBus.getDefault().register(this);
        imServiceConnector.connect(getActivity());
        super.init(curView);
        listview = (XListView)curView.findViewById(R.id.quanz_qz_list);
        progress_bar = (ProgressBar) curView.findViewById(R.id.progress_bar);
        progress_bar.setVisibility(View.VISIBLE);
        listview.setVisibility(View.GONE);
        initRes();
        inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        list = new ArrayList<QuanzQzMessageDetail>();
        getUrlsll();
        listview.setPullLoadEnable(false);
        initPopWindow();
        adapter = new QuanzDynamicAdapter(getActivity(), replyWindow, editWindow, new Quanzflush());
        adapter.setData(list);
        listview.setAdapter(adapter);
        listview.setFocusableInTouchMode(true);
        DisplayMetrics  dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        screenHeight = dm.heightPixels;  //屏幕高
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);  //状态栏高
        }
        curView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                getKeyboardHeight();
            }
        });
        listview.setXListViewListener(this);
        mHandler = new Handler();
        return curView;
    }

    /*评论输入框与底部对齐*/
    private int getKeyboardHeight() {

        Rect r = new Rect();
        curView.getWindowVisibleDisplayFrame(r);
        int visibleHeight = r.height();
        if (mVisibleHeight == 0) {
            mVisibleHeight = visibleHeight;
            return 0;
        }
        if (mVisibleHeight == visibleHeight) {
            return 0;
        }
        mVisibleHeight = visibleHeight;
        int j = screenHeight - result;
        if (j!=mVisibleHeight){
            mEditHeight = editView.getHeight();
            mHoadHeight = topBar.getHeight();
            int off = j - mVisibleHeight - mEditHeight - mHoadHeight+result;
            if (adapter == null) {
                return 0;
            }
            if (adapter.getCount()+2 == id + 1) {
                listview.setSelection(listview.getBottom());
            } else {
                listview.setSelectionFromTop(id + 1, off);
            }
        }
        return mVisibleHeight;
    }



    private void init(IMService imService) {

        if (imService == null) {
            return;
        }
        final UserEntity loginContact = imService.getLoginManager().getLoginInfo();
        if (loginContact == null) {
            return;
        }
        IMBaseImageView portraitImageView = (IMBaseImageView)curView.findViewById(R.id.user_portrait);
        portraitImageView.setDefaultImageRes(R.drawable.tt_default_user_portrait_corner);
        portraitImageView.setCorner(15);
        portraitImageView.setImageResource(R.drawable.tt_default_user_portrait_corner);
     //   portraitImageView.setImageUrl(loginContact.getAvatar());
        portraitImageView.setImageUrl(RegisterSp.instance().getSpDetailedInfo().getDetailedHeadPortrait());
    }



    /**
     * @Description 初始化资源
     */
    private void initRes() {
        // 设置标题栏
        mHeadViw = LayoutInflater.from(getActivity()).inflate(R.layout.quanz_qz_head, null);

        TextView mHeadNc = (TextView) mHeadViw.findViewById(R.id.mHeadNc);
        String nick = RegisterSp.instance().getSpDetailedInfo().getDetailedNickName();
        mHeadNc.setText(nick);
        View MyHead = mHeadViw.findViewById(R.id.user_portrait);
        MyHead.setOnClickListener(this);

        listview.addHeaderView(mHeadViw, null, false);
      //  hideTopRightButton();
        setTopRightButton(R.drawable.photo1);
        topRightBtn.setOnClickListener(this);
        setTopTitle(getActivity().getString(R.string.page_quanz_qz));
        setTopLeftButton(R.drawable.tt_top_back);
        topLeftContainerLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                getActivity().finish();
            }
        });
        setTopLeftText(getResources().getString(R.string.top_left_back));
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            }
        });
    }

    public void onEventMainThread(QuanzQzMessageDetail event) {
        list.add(0,event);
        XListD();
        adapter.notifyDataSetChanged();
        //EventBus.getDefault().unregister(this);//卸载注册事件
    }

    public void getUrlsll() {

        login_name = LoginSp.instance().getLoginIdentity().getLoginName();
        login_password = LoginSp.instance().getLoginIdentity().getPwd();

        new AsyncTask<String, Void, Object>() {
            protected void onPostExecute(Object result) {
                super.onPostExecute(result);
          //可以更新UI
                analysiss(result.toString());
                XListD();
                adapter.notifyDataSetChanged();
            }
            protected Object doInBackground(String... params) {
                String result = GETUtil.instance().sendGet(GETUtil.instance().getRequestText("public", "Index", "getFriendsTimeLine", login_name, login_password, null,"","0","0","10","1",null));
                CommentReply(result);
                return result;
            }
        }.execute();
    }

    public void XListD(){
        if (list.size()>0){
            listview.setPullLoadEnable(true);
            if (list.size()<4){
                listview.mFooter2();
            }else {
                listview.mFooter();
            }
        }else if (list.size()==0){
            listview.mFooter1();
            listview.setPullLoadEnable(true);
        }
    }

    public void analysiss(String result){
        progress_bar.setVisibility(View.GONE);
        listview.setVisibility(View.VISIBLE);
        try {
            JSONObject array = new JSONObject(result);
            JSONArray data = array.getJSONArray("data");
            if ("[]".equals(data.toString())){
                return;
            }
            JSONObject obj;
            for (int i=0;i<data.length();i++){
                obj=data.getJSONObject(i);
                data(obj);
            }
        }catch (Exception e) {
            System.out.println("1111111Qz  " + e.getMessage());
        }
    }

    private void data(final JSONObject obj) throws JSONException {

        if (obj==null)
            return;
        QuanzQzMessageDetail messageDetail = new QuanzQzMessageDetail();
        messageDetail.id = 0;
        messageDetail.friendId = Integer.parseInt(obj.getString("feed_id"));
        messageDetail.userId =obj.getString("uid");
        messageDetail.photo = obj.getString("avatar_middle");
        messageDetail.shareType = 0;
        messageDetail.name = obj.getString("uname");
        messageDetail.linkUrl = "";
        messageDetail.contentText = obj.getString("content");
        messageDetail.replyCount = 1;
        if (obj.getString("type").equals("post")){
            messageDetail.images="";
        }else if (obj.getString("type").equals("postimage")){
            if (obj.getString("has_attach").equals("0")){
                messageDetail.images="";
            }else if (obj.getString("has_attach").equals("1")){
                String attach=obj.getString("attach");
                messageDetail.images=attach.toString().replace("\\","");
            }
        }else{
            messageDetail.images="";
        }
        messageDetail.sendDate = obj.getString("ctime")+":00";
        if (obj.getString("diggs").equals("null")){
            messageDetail.favourName = "";
        }else{
            if (obj.getString("diggs").equals("[]")){
                messageDetail.favourName = "";
            }
            JSONArray diggs = obj.getJSONArray("diggs");
            String mName="";
            JSONObject nick=null;
            for (int i=0;i<diggs.length();i++){
                nick=diggs.getJSONObject(i);
                JSONObject user=nick.getJSONObject("user");
                if (mName!=""){
                    if (user.getString("uid").equals(String.valueOf(LoginSp.instance().getLoginIdentity().getLoginId()))){
                        mName=user.getString("nick")+"、"+mName;
                        messageDetail.favour="qwe";
                    }else{
                        mName=mName+"、"+user.getString("nick");
                    }
                }else{
                    mName=user.getString("nick");
                    if (user.getString("uid").equals(String.valueOf(LoginSp.instance().getLoginIdentity().getLoginId()))){
                        messageDetail.favour="qwe";
                    }
                }
            }
            messageDetail.favourName=mName;
        }

        ArrayList<QuanzQzReply> list_reply = new ArrayList<QuanzQzReply>();
        Map<String,QuanzQzReply> comrep=map1.get(obj.getString("feed_id"));
        if (comrep.size()!=0){
            for (int i=0;i<comrep.size();i++){
                list_reply.add(comrep.get(i+""));
            }
        }
        messageDetail.replyList =list_reply;
        list.add(messageDetail);
    }


    private void CommentReply(String result){
        try {
            JSONObject array = new JSONObject(result);
            JSONArray data = array.getJSONArray("data");
            JSONObject obj;
            map1 = new Hashtable<String,Map<String,QuanzQzReply>>();
            for (int i=0;i<data.length();i++){
                obj=data.getJSONObject(i);
                String feed_id=obj.getString("feed_id");
                String Feed_for_comments = GETUtil.instance().sendGet(GETUtil.instance().getRequestText("public", "Index", "getComment", login_name, login_password, feed_id, null, null, null, null, null, ""));
                JSONObject JFeed_for_comments = new JSONObject(Feed_for_comments);
                String Jdata = JFeed_for_comments.getString("data");
                map = new HashMap<String,QuanzQzReply>();
                if (Jdata.equals("")){

                }else{
                    JSONArray Jdata1 = new JSONArray(Jdata);
                    int Jbz=0;
                    for (int j=0;j<Jdata1.length();j++){
                        JSONObject Jobj= Jdata1.getJSONObject(j);
                        JSONObject user_info=Jobj.getJSONObject("user_info");
                        String content = Jobj.getString("content");
                        QuanzQzReply reply  = new QuanzQzReply();
                        if (content.indexOf("@")>0){
                            reply.content = content.split("：")[1];
                            JSONObject to_uid_user_info = Jobj.getJSONObject("to_uid_user_info");//这里是回复了谁的详细信息
                            reply.replyName = content.split("：")[0].split("@")[1];//获取回复谁的名字

                        }else{
                            reply.content = content;
                            reply.replyName = "";
                        }
                        reply.userId = Jobj.getString("uid");
                        reply.friendId =Integer.valueOf(Jobj.getString("comment_id"));//就是在回复数据库中的id  ***
                        reply.id = Integer.valueOf(Jobj.getString("row_id"));
                        reply.sendName = user_info.getString("nick");
                        reply.f_friendId = Integer.valueOf(feed_id);
                        map.put(Jbz+"",reply);//feed_id
                        Jbz++;
                    }
                }
                map1.put(feed_id, map);
            }
        }catch (Exception e) {
            System.out.println("1111111Qz  " + e.getMessage());
        }
    }

    /**
     * 初始化popWindow
     */
    private void initPopWindow() {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.quanz_qz_reply_popupwindow, null);
               // getLayoutInflater().inflate(R.layout.quanz_qz_reply_popupwindow, null);
        replyWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, true);
        replyWindow.setAnimationStyle(R.style.popupWindowAnimation);// 进入 退出动画
        discuss = (ImageButton) view.findViewById(R.id.discuss);
        favuor = (ImageButton) view.findViewById(R.id.favuor);
        favuorCancle = (ImageButton) view.findViewById(R.id.favuor_cancle);
        replyWindow.setBackgroundDrawable(getResources().getDrawable(R.color.default_light_black_color));
        replyWindow.setOutsideTouchable(true);
        discuss.setOnClickListener(this);
        favuor.setOnClickListener(this);
        favuorCancle.setOnClickListener(this);
        editView = LayoutInflater.from(getActivity()).inflate(R.layout.quanz_qz_repy_edit, null);
        editWindow = new PopupWindow(editView, LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT, true);
        editWindow.setBackgroundDrawable(getResources().getDrawable(
                R.color.white));
        editWindow.setOutsideTouchable(true);

        reply_emo_btn = (ImageView) editView.findViewById(R.id.reply_emo_btn);
        replyEdit = (EditText) editView.findViewById(R.id.reply);
        sendBtn = (TextView) editView.findViewById(R.id.send_reply);
        emo_layout_publish = editView.findViewById(R.id.emo_layout_publish);
        emoGridView = (EmoGridView) editView.findViewById(R.id.emo_gridview_publish);
        LinearLayout.LayoutParams paramEmoLayout = (LinearLayout.LayoutParams) emo_layout_publish.getLayoutParams();
        if (keyboardHeight > 0) {
            paramEmoLayout.height = keyboardHeight;
            emo_layout_publish.setLayoutParams(paramEmoLayout);
        }
        emoGridView.setOnEmoGridViewItemClick(onEmoGridViewItemClick);
        emoGridView.setAdapter();
    }


    /**
     * 显示回复评论框
     *
     *  // @param reply
     */
    private void showDiscuss(int posotion) {
        id = posotion+2;
        replyEdit.setFocusable(true);
        replyEdit.requestFocus();
        // 设置焦点，不然无法弹出输入法
        editWindow.setFocusable(true);
        // 以下两句不能颠倒
        editWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        editWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        int[] location = new int[2];
        curView.getLocationInWindow(location);
        //editWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        editWindow.showAtLocation(curView, Gravity.BOTTOM, 0, 0);
        // 显示键盘
        manager = (InputMethodManager) getActivity().getSystemService(getActivity().INPUT_METHOD_SERVICE);
        manager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
        editWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                manager.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                // manager.hideSoftInputFromWindow(curView.getWindowToken(),0);
            }
        });
        replyWindow.dismiss();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.discuss:
                //showDiscuss();
                break;
            case R.id.favuor:
                System.out.println("11111787878");
                break;
            case R.id.right_btn:
                IMUIHelper.openQuanzQzPublishActivity(QuanzQzFragment.this.getActivity(), 0);
                break;
            case R.id.user_portrait:
                IMUIHelper.openQzMyPhotoAlbumActivity(QuanzQzFragment.this.getActivity(), 0);
                break;
        }

    }


    @Override
    protected void initHandler() {

    }

    private void onLoad() {
        listview.stopRefresh();
        listview.stopLoadMore();
    }

    @Override
    public void onRefresh() {  //下拉刷新

        new AsyncTask<String, Void, Object>() {
            protected void onPostExecute(Object result) {
                super.onPostExecute(result);
                //可以更新UI
                Upwardmark=2;
                list.clear();
                analysiss(result.toString());
                XListD();
                adapter.notifyDataSetChanged();
                onLoad();

            }
            protected Object doInBackground(String... params) {
                String result = GETUtil.instance().sendGet(GETUtil.instance().getRequestText("public", "Index", "getFriendsTimeLine", login_name, login_password, null,"","0","0","10","1",null));
                CommentReply(result);
                return result;
            }
        }.execute();
    }

    @Override
    public void onLoadMore() {  //上拉加载更多
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {

                    new AsyncTask<String, Void, Object>() {
                        protected void onPostExecute(Object result) {
                            super.onPostExecute(result);
                            //可以更新UI
                            try {
                                JSONObject array = new JSONObject(result.toString());
                                JSONArray data = array.getJSONArray("data");
                                if (data.toString().equals("[]")) {
                                    listview.mFootYc();
                                }else{
                                    Upwardmark++;
                                    analysiss(result.toString());
                                    XListD();
                                    adapter.notifyDataSetChanged();
                                    onLoad();
                                }
                            }catch (Exception e) {
                                System.out.println("1111111Qz  " + e.getMessage());
                            }
                        }
                        protected Object doInBackground(String... params) {
                            String result = GETUtil.instance().sendGet(GETUtil.instance().getRequestText("public", "Index", "getFriendsTimeLine", login_name, login_password, null,"","0","0","10", String.valueOf(Upwardmark),null));
                            CommentReply(result);
                            return result;
                        }
                    }.execute();
            }
        }, 2000);
    }
    static int edit_height=0;
    @Override
    public void onSoftChange(PublishLayout.SoftState softState, int softHeight) {
        Log.d("sxun", "SoftState:" + softState + ";softHeight:" + softHeight);
        PublishLayout.SoftState keyboard_show = softState;
        if (softState == PublishLayout.SoftState.SHOW && softHeight >0){
            keyboardHeight=softHeight;
            LinearLayout.LayoutParams paramEmoLayout = (LinearLayout.LayoutParams) emo_layout_publish.getLayoutParams();
            if (keyboardHeight > 0) {
                paramEmoLayout.height = keyboardHeight;
                emo_layout_publish.setLayoutParams(paramEmoLayout);
            }

//            if (edit_height == 0){
//                int height = getActivity().getWindowManager().getDefaultDisplay().getHeight();
//                edit_height = height - softHeight - 150;
//                ViewGroup.LayoutParams layoutParams = messageEdt.getLayoutParams();
//                layoutParams.height = edit_height;
//                messageEdt.setLayoutParams(layoutParams);
//                Log.i("sxun","edit height:"+edit_height);
//            }
//            if (emoLayout.getVisibility()== View.VISIBLE){
//                paramEmoLayout.height = 0;
//                emoLayout.setLayoutParams(paramEmoLayout);
//                emoLayout.setVisibility(View.GONE);
//                emoLayout.setVisibility(View.VISIBLE);
//            }

        }else{
            //emoLayout.setVisibility(View.GONE);
        }
    }
    private EmoGridView.OnEmoGridViewItemClick onEmoGridViewItemClick = new EmoGridView.OnEmoGridViewItemClick() {
        @Override
        public void onItemClick(int facesPos, int viewIndex) {
            int deleteId = (++viewIndex) * (SysConstant.pageSize - 1);
            if (deleteId > Emoparser.getInstance(getActivity()).getResIdList().length) {
                deleteId = Emoparser.getInstance(getActivity()).getResIdList().length;
            }
            if (deleteId == facesPos) {
                String msgContent = replyEdit.getText().toString();
                if (msgContent.isEmpty())
                    return;
                if (msgContent.contains("["))
                    msgContent = msgContent.substring(0, msgContent.lastIndexOf("["));
                replyEdit.setText(msgContent);
            } else {
                int resId = Emoparser.getInstance(getActivity()).getResIdList()[facesPos];
                String pharse = Emoparser.getInstance(getActivity()).getIdPhraseMap()
                        .get(resId);
                int startIndex = replyEdit.getSelectionStart();
                Editable edit = replyEdit.getEditableText();
                if (startIndex < 0 || startIndex >= edit.length()) {
                    if (null != pharse) {
                        edit.append(pharse);
                    }
                } else {
                    if (null != pharse) {
                        edit.insert(startIndex, pharse);
                    }
                }
            }
            Editable edtable = replyEdit.getText();
            int position = edtable.length();
            Selection.setSelection(edtable, position);
        }
    };

    public class Quanzflush implements FlushListView {

        @Override
        public void flush() {
            adapter.notifyDataSetChanged();
        }

        @Override
        public void showDiscussDialog(int posotion) {
            showDiscuss(posotion);
        }

        @Override
        public void getReplyByTrendId(Object tag) {

        }

        @Override
        public void showFavour() {
            adapter.notifyDataSetChanged();
        }

        @Override
        public void getViewPosition(int position) {

        }

        @Override
        public void delParise(String valueOf) {

        }

        @Override
        public void showCancle(QuanzQzMessageDetail friend) {

        }

        @Override
        public void saveReply(QuanzQzReply reply) {

        }

        @Override
        public void addTrendParise(String trendId) {
            // TODO Auto-generated method stub

            Log.i("sxun", "addTrendParise  id: "+trendId);
            adapter.notifyDataSetChanged();
        }

        @Override
        public void delTrendById(String trendId) {
            // TODO Auto-generated method stub
            Log.i("sxun", "delTrendById  id: "+trendId);
            adapter.notifyDataSetChanged();
        }

        @Override
        public void showDel(int size) {
            // TODO Auto-generated method stub
            if (size>0){
                listview.setPullLoadEnable(true);
                if (size<4){
                    listview.mFooter2();
                }else {
                    listview.mFooter();
                }
            }else if (size==0){
                listview.mFooter1();
                listview.setPullLoadEnable(true);
            }
        }

        @Override
       public void handReply( View view) {
//            // TODO Auto-generated method stub
            System.out.println("778888888888887777");

            if (emo_layout_publish.getVisibility() == View.VISIBLE) {
                if (!replyEdit.hasFocus()) {
                    replyEdit.requestFocus();
                }
                emo_layout_publish.setVisibility(View.GONE);
                inputManager.toggleSoftInputFromWindow(replyEdit.getWindowToken(), 1, 0);
                if (keyboardHeight == 0) {
                    emo_layout_publish.setVisibility(View.GONE);
                }
            }else if (emo_layout_publish.getVisibility() == View.GONE) {
                inputManager.hideSoftInputFromWindow(replyEdit.getWindowToken(), 0);
                emo_layout_publish.setVisibility(View.VISIBLE);
                emoGridView.setVisibility(View.VISIBLE);
            }

        }
    }
}
